//package pkg10192;

import java.io.*;
import java.math.*;
import java.util.*;
import java.text.*;
import java.lang.*;

public class Main {

    BufferedReader reader;
    int[][] cando;

    public static void main(String[] args) throws IOException {
        Main ob = new Main();
        ob.run();
        System.exit(0);
    }

    public void run() throws IOException {
        // reader = new BufferedReader( new FileReader("in.txt") );
        reader = new BufferedReader(new InputStreamReader(System.in));
        String[] line = new String[2];
        int cases = 1;
        while ((line[0] = reader.readLine()) != null) {
            if (line[0].compareTo("#") == 0) {
                break;
            }
            line[1] = reader.readLine();
            proc(line, cases);
            ++cases;
        }
    }

    public void proc(String[] line, int cases) throws IOException {
        int m = line[0].length();
        int n = line[1].length();

        cando = new int[m + 10][n + 10];
        int i, j;
        for (i = 0; i <= m; ++i) {
            Arrays.fill(cando[i], 0);
        }

        for (i = 1; i <= m; ++i) {
            for (j = 1; j <= n; ++j) {
                if (line[0].charAt(i - 1) == line[1].charAt(j - 1)) {
                    cando[i][j] = cando[i - 1][j - 1] + 1;
                } else {
                    cando[i][j] = Math.max(cando[i - 1][j], cando[i][j - 1]);
                }
            }
        }
        System.out.format("Case #%d: you can visit at most %d cities.\n", cases, cando[m][n]);
    }
}
